<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ProjectMadaktariMVC.Models.Patient>" %>
<div class="innerContent">
    <% using (Html.BeginForm())
       using (var db = ProjectMadaktariMVC.Models.DBFactory.CreateContext())
       {%>
    <div class="form_block">
        <span class="form_label"><label for="FirstName">First Name</label></span>
        <%= Html.TextBox("FirstName", Model.FirstName)%>
        <%= Html.ValidationMessage("FirstNameerr")%>
    </div>
    <div class="form_block">
        <span class="form_label"><label for="LastName">Last Name</label></span>
        <%= Html.TextBox("LastName", Model.LastName)%>
        <%= Html.ValidationMessage("LastNameerr")%>
    </div>
    <div class="form_block">
        <span class="form_label"><label for="Gender">Gender</label></span>
        <%= Html.RadioButton("Gender", "Male", ((Model.Gender == null) ? false : Model.Gender.Equals("Male")))%>
        Male
        <%= Html.RadioButton("Gender", "Female", ((Model.Gender == null) ? false : Model.Gender.Equals("Female")))%>
        Female
        <%= Html.ValidationMessage("Gendererr")%>
    </div>
    <div class="form_block">
        <span class="form_label"><label for="DateOfBirth">Date of Birth</label></span>
        <%= Html.TextBox("DateOfBirth", Model.DateOfBirth == null ? "" : ((DateTime)Model.DateOfBirth).ToString("M/dd/yyyy"), new { @class = "datefield" })%>
        <%= Html.ValidationMessage("DateOfBirtherr")%>
    </div>
    <div class="form_block">
        <span class="form_label"><label for="RegistrationNumber">Registration Number</label></span>
        <%= Html.TextBox("RegistrationNumber", Model.RegistrationNumber)%>
        <%= Html.ValidationMessage("RegistrationNumbererr")%>
    </div>
    <div class="form_block">
        <span class="form_label"><label for="CellNumber">Cell Phone</label></span>
        <%= Html.TextBox("CellNumber", Model.CellNumber)%>
        <%= Html.ValidationMessage("CellNumbererr")%>
    </div>
    <div class="form_block">
        <span class="form_label"><label for="Tribe1Id">Tribe 1</label></span>
        <%=ProjectMadaktariMVC.Helpers.ConfigurationHelper.TribeDropDown(db, "Tribe1Id", Model.Tribe1 == null ? string.Empty : Model.Tribe1.Name) %>
        <%= Html.TextBox("CustomTribe1", Model.CustomTribe1)%>
    </div>
    <div class="form_block">
        <span class="form_label"><label for="Tribe2Id">Tribe 2</label></span>
        <%=ProjectMadaktariMVC.Helpers.ConfigurationHelper.TribeDropDown(db, "Tribe2Id", Model.Tribe2 == null ? string.Empty : Model.Tribe2.Name) %>
        <%= Html.TextBox("CustomTribe2", Model.CustomTribe2)%>
    </div>
    <span />
    <input type="submit" value="Submit" />
    <% 
        if (Model.Id == 0)
        {
            Response.Write(Html.ActionLink("Cancel", "Index", "Home"));
        }
        else
        {
            Response.Write(Html.ActionLink("Cancel", "View", new { id = Model.Id }));
        }
    %>
    <% } %>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('.datefield').datepicker({ changeYear: true, changeMonth: true, maxDate: '+0D', yearRange: '-120:+1' });

        $('#Tribe1Id').change(function () {
            ToggleDisplay("Tribe1Id", "CustomTribe1");
        });

        $('#Tribe2Id').change(function () {
            ToggleDisplay("Tribe2Id", "CustomTribe2");
        });

        ToggleDisplay("Tribe1Id", "CustomTribe1");
        ToggleDisplay("Tribe2Id", "CustomTribe2");
    });

    function ToggleDisplay(e1, e2) {
        var v
                = ($('#' + e1).val() == -1)
                ? "inline"
                : "none";

        $('#' + e2).css('display', v);
    }
</script>
